<script setup lang="ts">
import { getPlatApplyDetail } from "@/api/other/platApply";
import { FileUpload } from "@/components/common/FileUpload";
import { formatDate, isCanPreview } from "@/utils/common";
import { ref, watch } from "vue";
import { FormProps } from "../utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: null,
    title: "新增",
    finalFiles: "",
    finalResult: "",
    finalResultFiles: "",
    masterUserId: null,
    masterUserName: null,
    userIds: null,
    shenMasterName: null,
    shenPartName: null,
    firstAccountDate: "",
    secondAccountDate: "",
    score: null,
    writeObjective: "",
    writeObjectiveFiles: "",
    examineStatus: 0,
    examineDesc: ""
  }),
  dataId: null,
  userList: null
});

watch(
  () => props.dataId,
  async newValue => {
    if (!newValue) {
      return;
    }
    getPlatApplyDetail({ id: newValue }).then(res => {
      newFormInline.value = res.data;
    });
  },
  { immediate: true }
);

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    label-width="160px"
    class="mr-12"
  >
    <el-form-item label="平台名称" prop="finalResult">
      <div>{{ newFormInline.finalResult || "--" }}</div>
    </el-form-item>
    <el-form-item label="平台级别" prop="writeObjective">
      <div>{{ newFormInline.writeObjective || "--" }}</div>
    </el-form-item>

    <el-form-item label="申报负责人" prop="shenMasterName">
      <div>{{ newFormInline.masterUserName || "--" }}</div>
    </el-form-item>
    <el-form-item label="申报参与人" prop="shenPartName">
      <div>
        {{
          newFormInline.userList
            ? newFormInline.userList.map(v => v.name).join(",")
            : "--"
        }}
      </div>
    </el-form-item>
    <el-form-item label="申报日期" prop="firstAccountDate">
      <div>
        {{ formatDate(newFormInline.firstAccountDate, "--") }}
      </div>
    </el-form-item>
    <el-form-item label="获批日期" prop="hireDate">
      <div>
        {{ formatDate(newFormInline.secondAccountDate, "--") }}
      </div>
    </el-form-item>
    <el-form-item label="通知文件" prop="writeObjectiveFiles">
      <FileUpload
        v-model="newFormInline.writeObjectiveFiles"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>
    <el-form-item label="申报文件" prop="finalResultFiles">
      <FileUpload
        v-model="newFormInline.finalResultFiles"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>
    <el-form-item label="获批文件" prop="finalFiles">
      <FileUpload
        v-model="newFormInline.finalFiles"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>
    <el-form-item label="积分" prop="score">
      <div>{{ newFormInline.score }}</div>
    </el-form-item>
    <el-form-item label="审核状态" prop="score">
      <div>
        <el-tag v-if="newFormInline.examineStatus === 0" type="warning"
          >审核中</el-tag
        >
        <el-tag v-else-if="newFormInline.examineStatus === 1" type="primary"
          >已审核</el-tag
        >
        <el-tag v-else type="danger">已驳回</el-tag>
      </div>
    </el-form-item>
    <el-form-item label="驳回原因" prop="score">
      <div>{{ newFormInline.examineDesc || "--" }}</div>
    </el-form-item>
  </el-form>
</template>
